const express = require("express");
const router = express.Router();
const pageController = require("./controller/pageController");
const adminUserController = require("./controller/adminUserController");
const categoryController = require("./controller/adminCategoryController");

//监听不同请求

//返回一个主页
router.get("/", (req, res) => {
  pageController.getIndex(req, res);
});
// 项目会约定好，我们在url厘米的格式，是否携带.html后缀
// 阿里百秀项目约定好，所有的页面，都是不带.html后缀的
router.get("/index", (req, res) => {
  pageController.getIndex(req, res);
});

//返回后台主页
router.get("/admin", (req, res) => {
  pageController.getAdminIndex(req, res);
});
router.get("/admin/index", (req, res) => {
  pageController.getAdminIndex(req, res);
});

// 返回后台分类管理

router.get("/admin/Categories", (req, res) => {
  pageController.getAdminCategory(req, res);
});

router.get("/admin/comments", (req, res) => {
  pageController.getAdminComments(req, res);
});

router.get("/admin/post-add", (req, res) => {
  pageController.getAdminPostAdd(req, res);
});

router.get("/admin/password-reset", (req, res) => {
  pageController.getAdminPasswordReset(req, res);
});

router.get("/admin/posts", (req, res) => {
  pageController.getAdminPosts(req, res);
});

router.get("/admin/profile", (req, res) => {
  pageController.getAdminProfile(req, res);
});

router.get("/admin/settings", (req, res) => {
  pageController.getAdminSettings(req, res);
});

router.get("/admin/slides", (req, res) => {
  pageController.getAdminSlides(req, res);
});

router.get("/admin/users", (req, res) => {
  pageController.getAdminUsers(req, res);
});
router.get("/admin/login", (req, res) => {
  pageController.getAdminLogin(req, res);
});

//监听登录请求
router.post("/admin_do_login", (req, res) => {
  adminUserController.adminDoLogin(req, res);
});
// 监听处理删除用户的请求
router.get("/delete_user_by_id", (req, res) => {
  adminUserController.deleteUserById(req, res);
});

//监听获取头像和昵称的请求
router.get("/get_user_head_and_nickname", (req, res) => {
  adminUserController.getUserHeadAndNickName(req, res);
});

//添加分类数据的请求
router.post("/addNewCategory", (req, res) => {
  categoryController.addNewCategory(req, res);
});

//删除分类数据的请求
router.get("/deleteCategoryById", (req, res) => {
  categoryController.deleteCategoryById(req, res);
});

router.get("/getCategoryById", (req, res) => {
  // console.log(req);
  categoryController.getCategoryById(req, res);
});

//编辑分类数据的请求
router.post("/editCategoryById", (req, res) => {
  categoryController.editCategoryById(req, res);
});
//全选或者多选，然后批量删除
router.get("/deleteMultiple", (req, res) => {
  categoryController.deleteMultiple(req, res);
});

const postController = require("./controller/adminPostController");
//根据分页获取文章数据
router.post("/getPostByPage", (req, res) => {
  postController.getPostByPage(req, res);
});
//暴露router
module.exports = router;
